//
//  DefalutViewController.swift
//  Mediaplayer
//
//  Created by bin hu on 2025/7/11.
//

import UIKit

enum FounctionsType: String {
    case defalut = "defalut"
    case video = "视频"
    case music = "音乐"
    case reader = "阅读"
    case comic = "漫画"
    case download = "下载"
    case theme = "主题"
    case topic = "圈子"
    case dynamic = "多域名"
}

class DefalutViewController: BaseViewController {
    
    private let functions:[FounctionsType] = [.video,.music,.reader,.comic,.download,.theme,.topic,.dynamic]
    
    private lazy var tableView:UITableView = {
        let tableV = UITableView(frame: .zero, style: .plain)
        tableV.backgroundColor = .clear
        tableV.delegate = self
        tableV.dataSource = self
        tableV.bounces = false
        tableV.separatorStyle = .singleLine
        tableV.rowHeight = 60.0
        tableV.showsVerticalScrollIndicator = false
        if #available(iOS 15.0, *) {
            tableV.sectionHeaderTopPadding = 0
        } else {}
        tableV.contentInsetAdjustmentBehavior = .never
        tableV.register(UITableViewCell.self, forCellReuseIdentifier: "UITableViewCellIdentifier")
        view.addSubview(tableV)
        return tableV
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
  
}

extension DefalutViewController:UITableViewDelegate {
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let current:FounctionsType = functions[indexPath.row]
        guard let keyWindow = (UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.window else {
            return
        }
        keyWindow.rootViewController = BaseTabBarController(functionType: current)
    }
}

extension DefalutViewController:UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return functions.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCellIdentifier", for: indexPath)
        cell.textLabel?.text = functions[indexPath.row].rawValue
        cell.selectionStyle = .none
        return cell
    }
    
}
